package controller;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;

import hibernate.OrderstabDAO;

public class CountOrder implements Action {

	private int parkId;
	private int year;
	private String month;
	private int day;
	private int totalOrders;
	private int totalPrice;
	public static List list=new ArrayList();
	
	public List getList() {
		return list;
	}
	
	public int getYear() {
		return year;
	}
	public void setYear(int year) {
		this.year = year;
	}
	public String getMonth() {
		return month;
	}
	public void setMonth(String month) {
		this.month = month;
	}
	public int getDay() {
		return day;
	}
	public void setDay(int day) {
		this.day = day;
	}
	
	public int getTotalOrders() {
		return totalOrders;
	}
	public void setTotalOrders(int totalOrders) {
		this.totalOrders = totalOrders;
	}
	public int getTotalPrice() {
		return totalPrice;
	}
	public void setTotalPrice(int totalPrice) {
		this.totalPrice = totalPrice;
	}
	public void setList(List list) {
		this.list = list;
	}

	public void countOrders(){
		int myMonth=0;
		OrderstabDAO orderstabDao=new OrderstabDAO();
		orderstabDao.getSession().beginTransaction();
		
		try
		{

			myMonth=Integer.parseInt(month);
			System.out.println(myMonth);
			ActionContext ctx = ActionContext.getContext();
			
			parkId=(Integer) ctx.getSession().get("parkID");
			System.out.println(parkId);
			list=orderstabDao.countOrders(parkId, year,myMonth, 0);
			orderstabDao.getSession().getTransaction().commit();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		finally
		{
			orderstabDao.getSession().close();
		}
		/*
		Object[] obj=(Object[]) list.get(0);
		System.out.println(obj[0]);
		*/
	}


	@Override
	public String execute() throws Exception {
		countOrders();
		return SUCCESS;
	}

}
